<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>UUID 生成器</title>
    <style>
      /* 基本页面样式 */
      body {
        font-family: 'Helvetica', 'Arial', sans-serif;
        background-color: #f5f7fa;
        margin: 0;
        padding: 20px;
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        color: #333;
        overflow: hidden; /* 禁止页面滚动 */
      }

      .container {
        background: #fff;
        padding: 20px;
        border-radius: 8px;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
        width: 100%;
        max-width: 600px;
      }

      h1 {
        color: #409eff;
        font-size: 26px;
        font-weight: 500;
        margin-bottom: 20px;
        text-align: center;
      }

      /* 输入框和复选框的容器 */
      .form-group {
        display: flex;
        justify-content: space-between;
        margin-bottom: 20px;
        align-items: center;
      }

      .form-group label {
        font-size: 14px;
        color: #606266;
      }

      /* 美化输入框 */
      .form-group input[type='number'],
      .form-group input[type='checkbox'] {
        display: inline-block;
        height: 34px;
        border-radius: 4px;
        font-size: 14px;
        color: #333;
        padding: 6px 10px;
        border: 1px solid #dcdfe6;
        outline: none;
        transition: all 0.3s ease;
      }

      .form-group input[type='number'] {
        width: 80px;
        box-sizing: border-box;
      }

      .form-group input[type='checkbox'] {
        width: auto;
        margin-left: 10px;
        padding: 0;
        height: auto;
        position: relative;
      }

      /* 输入框 focus 样式 */
      .form-group input[type='number']:focus {
        border-color: #409eff;
      }

      /* 复选框样式 */
      .form-group input[type='checkbox']:checked {
        background-color: #409eff;
        border-color: #409eff;
        box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.3);
      }

      .form-group input[type='checkbox']:focus {
        outline: none;
      }

      /* 美化按钮 */
      button {
        display: block;
        margin: 0 auto;
        background-color: #409eff;
        color: #fff;
        border: none;
        padding: 10px 20px;
        border-radius: 4px;
        cursor: pointer;
        font-size: 14px;
        transition: background-color 0.3s ease;
        margin-top: 20px;
      }

      button:hover {
        background-color: #66b1ff;
      }

      button:active {
        background-color: #3386d5;
      }

      /* UUID 列表样式 */
      .uuid-list {
        margin-top: 30px;
        height: 300px; /* 固定高度 */
        overflow-y: auto; /* 使 UUID 列表可滚动 */
        border-radius: 6px;
        padding: 15px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        position: relative;
      }

      /* 自定义滚动条样式 */
      .uuid-list::-webkit-scrollbar {
        width: 8px; /* 设置滚动条宽度 */
      }

      .uuid-list::-webkit-scrollbar-thumb {
        background-color: #409eff;
        border-radius: 4px; /* 圆角效果 */
      }

      .uuid-list::-webkit-scrollbar-thumb:hover {
        background-color: #66b1ff;
      }

      .uuid-list::-webkit-scrollbar-track {
        background: #f2f2f2;
        border-radius: 4px;
      }

      .uuid-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-radius: 6px;
        padding: 8px 16px;
        border-bottom: 1px solid #dcdfe6;
        word-wrap: break-word;
        word-break: break-all;
        font-size: 14px;
        transition: background-color 0.3s ease; /* 增加过渡效果 */
      }
      .uuid-item + .uuid-item {
        margin-top: 8px;
      }

      .uuid-item:hover {
        background-color: #e8f4ff; /* 更鲜明的蓝色 */
      }

      .uuid-item .uuid-number {
        font-weight: bold;
        color: #409eff;
        font-size: 14px;
        margin-right: 15px;
      }

      .uuid-item button {
        background-color: #67c23a;
        color: white;
        border: none;
        margin: 0;
        padding: 6px 12px;
        border-radius: 4px;
        cursor: pointer;
        font-size: 13px;
        transition: background-color 0.3s ease;
      }

      .uuid-item button:hover {
        background-color: #85d585;
      }

      .uuid-item button:active {
        background-color: #4cae34;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <h1>UUID 生成器</h1>

      <!-- 控制输入部分 -->
      <div class="form-group">
        <div>
          <label for="count">生成个数：</label>
          <input type="number" id="count" value="32" min="1" max="100" />
        </div>

        <div>
          <label for="dash">包含横线：</label>
          <input type="checkbox" id="dash" checked />
        </div>

        <div>
          <label for="uppercase">大写字母：</label>
          <input type="checkbox" id="uppercase" />
        </div>
      </div>

      <!-- 按钮 -->
      <button onclick="generateUUID()">生成 UUID</button>

      <!-- 显示生成的 UUID -->
      <div class="uuid-list" id="uuid-list"></div>
    </div>

    <script>
      // 改进后的 UUID v4 生成算法
      function generateUUIDString(includeDash = true, uppercase = false) {
        let uuid = crypto.randomUUID()

        // 如果不需要横线，移除横线
        if (!includeDash) {
          uuid = uuid.replace(/-/g, '')
        }

        // 如果需要大写字母，转换为大写
        if (uppercase) {
          uuid = uuid.toUpperCase()
        }

        return uuid
      }

      // 生成多个 UUID，并展示
      function generateUUID() {
        const count = parseInt(document.getElementById('count').value, 10)
        const includeDash = document.getElementById('dash').checked
        const uppercase = document.getElementById('uppercase').checked

        const uuidListContainer = document.getElementById('uuid-list')
        uuidListContainer.innerHTML = '' // 清空之前的 UUID

        for (let i = 0; i < count; i++) {
          const uuid = generateUUIDString(includeDash, uppercase)
          const uuidElement = document.createElement('div')
          uuidElement.classList.add('uuid-item')

          const uuidNumber = document.createElement('span')
          uuidNumber.classList.add('uuid-number')
          uuidNumber.textContent = `${i + 1}、`

          const uuidText = document.createElement('span')
          uuidText.textContent = uuid

          const copyButton = document.createElement('button')
          copyButton.textContent = '复制'
          copyButton.onclick = function () {
            navigator.clipboard.writeText(uuid).then(() => {
              alert('UUID 已复制到剪贴板')
            })
          }

          uuidElement.appendChild(uuidNumber)
          uuidElement.appendChild(uuidText)
          uuidElement.appendChild(copyButton)
          uuidListContainer.appendChild(uuidElement)
        }
      }
    </script>
  </body>
</html>
